package com.tiancheng.trade.order.vo.app.res;

import com.tiancheng.trade.order.model.QrOrder;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @Author: likailun
 * @Description: 支付记录实体
 * @Date: create in 2021/9/10 7:16 下午
 */
@Getter
@Setter
public class QrPayRecordQueryResVO {
    /**
     * 二维码单号
     */
    private String orderId;
    /**
     * 支付流水号
     */
    private String flowId;
    /**
     * 用户id
     */
    private String uid;
    /**
     * 申码场景，1-公交<br/>
     * @see com.cloud.trade.order.enums.QrSourceEnum
     */
    private String qrSource;
    /**
     * 订单金额
     */
    private String orderAmount;
    /**
     * 优惠金额
     */
    private String discount;
    /**
     * 支付金额
     */
    private String payAmount;
    /**
     * 退款金额
     */
    private String refundAmount;
    /**
     * 订单状态<br/>
     * WP-待支付,HC-已取消，AP-已支付
     */
    private String orderStatus;
    /**
     * 商户名称
     */
    private String merchantName;
    /**
     * 商户号
     */
    private String merchantCode;
    /**
     * 是原始的C2B消费或C2B预授权交易的凭证号
     */
    private String voucherNum;
    /**
     * 支付时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    protected LocalDateTime payTime;

    /**
     * 订单创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    protected LocalDateTime createDt;


    /**
     * 请求方自定义数据
     */
    private String reqReserved;

    public void init(QrOrder qrOrder){
        this.setOrderId(qrOrder.getOrderId());
        this.setFlowId(qrOrder.getFlowId());
        this.setUid(qrOrder.getUid());
        this.setQrSource(qrOrder.getQrSource());
        if(qrOrder.getOrderAmount()!=null && qrOrder.getOrderAmount()>0){
            this.setOrderAmount(new BigDecimal(qrOrder.getOrderAmount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).toString());
        }
        if(qrOrder.getDiscount()!=null && qrOrder.getDiscount()>0){
            this.setDiscount(new BigDecimal(qrOrder.getDiscount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).toString());
        }
        if(qrOrder.getPayAmount()!=null && qrOrder.getPayAmount()>0){
            this.setPayAmount(new BigDecimal(qrOrder.getPayAmount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).toString());
        }
        if(qrOrder.getRefundAmount()!=null&& qrOrder.getRefundAmount()>0){
            this.setRefundAmount(new BigDecimal(qrOrder.getRefundAmount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).toString());
        }
        this.setOrderStatus(qrOrder.getOrderStatus());
        this.setMerchantName(qrOrder.getMerchantName());
        this.setMerchantCode(qrOrder.getMerchantCode());
        this.setVoucherNum(qrOrder.getVoucherNum());
        this.setPayTime(qrOrder.getPayTime());
        this.setCreateDt(qrOrder.getCreateDt());
        this.setReqReserved(qrOrder.getReqReserved());
    }
}
